fix: joinUrl no longer collapses the URL scheme#2915
Merged
Conversation
joinUrl used path.Join, whose path.Clean collapses the // in a URL scheme,
so {{joinUrl "http://localhost" "p1" "p2"}} produced http:/localhost/p1/p2
instead of the documented http://localhost/p1/p2. Use net/url.JoinPath, which
preserves the scheme.
Member
|
Thanks! |
Contributor
Author
|
Done — added |
vmaerten
approved these changes
Jul 14, 2026
vmaerten
added a commit
that referenced
this pull request
Jul 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
joinUrlcollapses the//in a URL scheme, so it produces an invalid URL:The documented behavior (docs/reference/templating.md, "URLs" section) shows
http://localhost/path1/path2, so this is a clear bug — and it's the whole reasonjoinUrlexists separately fromjoinPath.Why
joinUrlwas implemented aspath.Join(elem...).path.Joinrunspath.Clean, which collapses consecutive slashes and destroys the//after the scheme.Fix
Use
net/url.JoinPath, which is purpose-built for joining URL path segments and preserves the scheme. The signature becomes(string, error), consistent with the siblingrelPath/absPathfuncs (filepath.Rel/filepath.Abs), and the template engine already supports funcs that return an error.Tests
Added
TestJoinUrlininternal/templater/funcs_test.gocovering scheme preservation, a base with an existing path, and trailing-slash handling.joinUrlshipped without a test in #2408, which is how this slipped through.